package com.sansi.pencilbook.service.impl;

import com.sansi.pencilbook.DO.Result;
import com.sansi.pencilbook.entity.Address;
import com.sansi.pencilbook.entity.UserAndAddress;
import com.sansi.pencilbook.mapper.UserAndAddressMapper;
import com.sansi.pencilbook.service.UserAndAddressServer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 功能说明:
 *
 * @author lsy13
 */
@Service
public class UserAndAddressServerImpl implements UserAndAddressServer {

    @Autowired
    private UserAndAddressMapper userAndAddressMapper;

    @Override
    public Result getAllAddress() {
        try {
            List<UserAndAddress> addresses = userAndAddressMapper.findAll();
            return addresses.size()>0 ? Result.ofSuccess(addresses.size(), addresses) :
                    Result.ofFailed("查询地址为空");
        } catch (Exception throwables) {
            System.out.println(throwables.getMessage());
            return Result.ofFailed("地址查询失败");
        }
    }
}
